<?php

/**
 * GeoLocation filter form base class.
 *
 * @package    symfony
 * @subpackage filter
 * @author     Francisco Calderón <fjcalderon@gmail.com>
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseGeoLocationFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'country'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('NfCountry'), 'add_empty' => true)),
      'region'      => new sfWidgetFormFilterInput(),
      'city'        => new sfWidgetFormFilterInput(),
      'postal_code' => new sfWidgetFormFilterInput(),
      'latitude'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'longitude'   => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'metro_code'  => new sfWidgetFormFilterInput(),
      'area_code'   => new sfWidgetFormFilterInput(),
    ));

    $this->setValidators(array(
      'country'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('NfCountry'), 'column' => 'iso')),
      'region'      => new sfValidatorPass(array('required' => false)),
      'city'        => new sfValidatorPass(array('required' => false)),
      'postal_code' => new sfValidatorPass(array('required' => false)),
      'latitude'    => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'longitude'   => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'metro_code'  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'area_code'   => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
    ));

    $this->widgetSchema->setNameFormat('geo_location_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'GeoLocation';
  }

  public function getFields()
  {
    return array(
      'id'          => 'Number',
      'country'     => 'ForeignKey',
      'region'      => 'Text',
      'city'        => 'Text',
      'postal_code' => 'Text',
      'latitude'    => 'Number',
      'longitude'   => 'Number',
      'metro_code'  => 'Number',
      'area_code'   => 'Number',
    );
  }
}
